package com.example.pixelyear.utils.dialog

import com.example.pixelyear.Interface.OnChooseColorClick
import com.example.pixelyear.R
import com.example.pixelyear.ui.base.BaseActivity
import com.example.pixelyear.utils.UIUtils
import com.example.pixelyear.utils.Utils
import com.example.pixelyear.utils.extension.setOnDoubleClickListener
import com.example.pixelyear.utils.extension.stringText
import kotlinx.android.synthetic.main.dialog_choose_color.view.*

class ChooseColorDialog(val context: BaseActivity) : BaseChooseColorDialog(context) {
    override fun getLayoutID(): Int {
        return R.layout.dialog_choose_color
    }

    override fun initAny() {

        rootView.Dialog_ChooseColor_Color.addOnColorChangedListener {
            if (it == -1)
                rootView.Dialog_ChooseColor_Text.setTextColor(UIUtils.getColor(R.color.white))
            else
                rootView.Dialog_ChooseColor_Text.setTextColor(it)

        }

        rootView.Dialog_ChooseColor_Sure.setOnDoubleClickListener {
            if (rootView.Dialog_ChooseColor_Text.stringText().isNotEmpty())
                if (rootView.Dialog_ChooseColor_Color.selectedColor == -1) {
                    Utils.showToast("颜色本来就是白色哦～")
                } else {
                    click?.click(
                        rootView.Dialog_ChooseColor_Color.selectedColor,
                        rootView.Dialog_ChooseColor_Text.stringText()
                    )
                }
            else Utils.showToast("颜色心语不能为空哦～")
        }
    }

    override fun show(color: Int, text: String) {
        super.show()
        rootView.Dialog_ChooseColor_Text.setTextColor(color)
        rootView.Dialog_ChooseColor_Text.setText(text)
    }

}